package com.bianmaba.beans.datacollection;

import com.alibaba.fastjson.JSONObject;
import com.bianmaba.spring.data.jpa.domain.entity.UuidIdentityEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.struts2.json.JSONUtil;

import javax.persistence.Entity;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CollectionTask extends UuidIdentityEntity {
    private String name;
    private String description;
    private String parameters;
    private String projectId;

    @ManyToOne(optional = false)
    @JoinTable(name = "CollectionTask_ref_CollectionInterface")
    private CollectionInterface collectionInterface;

    public static CollectionTask of(String taskId) {
        CollectionTask task = new CollectionTask();
        task.setId(taskId);
        return task;
    }

    public List<HashMap> getParameterMap() {
        List<HashMap> map = JSONObject.parseArray(this.parameters, HashMap.class);
        return map;
    }
}
